home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hobby / ast44src.zip / CALC.C < prev    next >
C/C++ Source or Header  |  1995-02-11  |  23KB  |  688 lines

  1. /*
  2. ** Astrolog (Version 4.40) File: calc.c
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (astara@u.washington.edu). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 1/29/1995.
  35. */
  36.  
  37. #include "astrolog.h"
  38.  
  39.  
  40. /*
  41. ******************************************************************************
  42. ** House Cusp Calculations.
  43. ******************************************************************************
  44. */
  45.  
  46. /* This is a subprocedure of ComputeInHouses(). Given a zodiac position,  */
  47. /* return which of the twelve houses it falls in. Remember that a special */
  48. /* check has to be done for the house that spans 0 degrees Aries.         */
  49.  
  50. int HousePlaceIn(rDeg)
  51. real rDeg;
  52. {
  53.   int i = 0;
  54.  
  55.   rDeg = Mod(rDeg + 0.5/60.0/60.0);
  56.   do {
  57.     i++;
  58.   } while (!(i >= cSign ||
  59.       (rDeg >= house[i] && rDeg < house[Mod12(i+1)]) ||
  60.       (house[i] > house[Mod12(i+1)] &&
  61.       (rDeg >= house[i] || rDeg < house[Mod12(i+1)]))));
  62.   return i;
  63. }
  64.  
  65.  
  66. /* For each object in the chart, determine what house it belongs in. */
  67.  
  68. void ComputeInHouses()
  69. {
  70.   int i;
  71.  
  72.   for (i = 1; i <= cObj; i++)
  73.     inhouse[i] = HousePlaceIn(planet[i]);
  74. }
  75.  
  76.  
  77. /* This house system is just like the Equal system except that we start */
  78. /* our 12 equal segments from the Midheaven instead of the Ascendant.   */
  79.  
  80. void HouseEqualMidheaven()
  81. {
  82.   int i;
  83.  
  84.   for (i = 1; i <= cSign; i++)
  85.     house[i] = Mod(MC-270.0+30.0*(real)(i-1));
  86. }
  87.  
  88.  
  89. /* This is a new house system similar in philosophy to Porphyry houses.   */
  90. /* Instead of just trisecting the difference in each quadrant, we do a    */
  91. /* smooth sinusoidal distribution of the difference around all the cusps. */
  92.  
  93. void HousePorphyryNeo()
  94. {
  95.   real delta;
  96.   int i;
  97.  
  98.   delta = (MinDistance(MC, Asc) - rDegQuad)/4.0;
  99.   house[sLib] = Mod(Asc+rDegHalf); house[sCap] = MC;
  100.   house[sAqu] = Mod(house[sCap] + 30.0 + delta   + is.rSid);
  101.   house[sPis] = Mod(house[sAqu] + 30.0 + delta*2 + is.rSid);
  102.   house[sSag] = Mod(house[sCap] - 30.0 + delta   + is.rSid);
  103.   house[sSco] = Mod(house[sSag] - 30.0 + delta*2 + is.rSid);
  104.   for (i = sAri; i < sLib; i++)
  105.     house[i] = Mod(house[i+6]-rDegHalf);
  106. }
  107.  
  108.  
  109. /* The "Whole" house system is like the Equal system with 30 degree houses, */
  110. /* where the 1st house starts at zero degrees of the sign of the Ascendant. */
  111.  
  112. void HouseWhole()
  113. {
  114.   int i;
  115.  
  116.   for (i = 1; i <= cSign; i++)
  117.     house[i] = Mod((SFromZ(Asc)-1)*30+ZFromS(i)+is.rSid);
  118. }
  119.  
  120.  
  121. /* In "null" houses, the cusps are always fixed to start at their cor-    */
  122. /* responding sign, i.e. the 1st house is always at 0 degrees Aries, etc. */
  123.  
  124. void HouseNull()
  125. {
  126.   int i;
  127.  
  128.   for (i = 1; i <= cSign; i++)
  129.     house[i] = Mod(ZFromS(i)+is.rSid);
  130. }
  131.  
  132.  
  133. /* Calculate the house cusp positions, using the specified algorithm. */
  134.  
  135. void ComputeHouses(housesystem)
  136. int housesystem;
  137. {
  138.   char sz[cchSzDef];
  139.  
  140.   if (RAbs(AA) > RFromD(rDegQuad-rAxis) && housesystem < 2) {
  141.     sprintf(sz,
  142.       "The %s system of houses is not defined at extreme latitudes.",
  143.       szSystem[housesystem]);
  144.     PrintError(sz);
  145.     Terminate(tcFatal);
  146.   }
  147.   switch (housesystem) {
  148.   case  1: HouseKoch();           break;
  149.   case  2: HouseEqual();          break;
  150.   case  3: HouseCampanus();       break;
  151.   case  4: HouseMeridian();       break;
  152.   case  5: HouseRegiomontanus();  break;
  153.   case  6: HousePorphyry();       break;
  154.   case  7: HouseMorinus();        break;
  155.   case  8: HouseTopocentric();    break;
  156.   case  9: HouseEqualMidheaven(); break;
  157.   case 10: HousePorphyryNeo();    break;
  158.   case 11: HouseWhole();          break;
  159.   case 12: HouseNull();           break;
  160.   default: HousePlacidus();
  161.   }
  162. }
  163.  
  164.  
  165. /*
  166. ******************************************************************************
  167. ** Star Position Calculations.
  168. ******************************************************************************
  169. */
  170.  
  171. /* This is used by the chart calculation routine to calculate the positions */
  172. /* of the fixed stars. Since the stars don't move in the sky over time,     */
  173. /* getting their positions is mostly just reading info from an array and    */
  174. /* converting it to the correct reference frame. However, we have to add    */
  175. /* in the correct precession for the tropical zodiac, and sort the final    */
  176. /* index list based on what order the stars are supposed to be printed in.  */
  177.  
  178. void ComputeStars(SD)
  179. real SD;
  180. {
  181.   int i, j;
  182.   real x, y, z;
  183.  
  184.   /* Read in star positions. */
  185.  
  186.   for (i = 1; i <= cStar; i++) {
  187.     x = stardata[i*6-6]; y = stardata[i*6-5]; z = stardata[i*6-4];
  188.     planet[oNorm+i] = RFromD(x*rDegMax/24.0+y*15.0/60.0+z*0.25/60.0);
  189.     x = stardata[i*6-3]; y = stardata[i*6-2]; z = stardata[i*6-1];
  190.     planetalt[oNorm+i] = RFromD(x+y/60.0+z/60.0/60.0);
  191.     /* Convert to ecliptic zodiac coordinates. */
  192.     EquToEcl(&planet[oNorm+i], &planetalt[oNorm+i]);
  193.     planet[oNorm+i] = Mod(DFromR(planet[oNorm+i])+rEpoch2000+SD);
  194.     planetalt[oNorm+i] = DFromR(planetalt[oNorm+i]);
  195.     ret[oNorm+i] = RFromD(rDegMax/26000.0/365.25);
  196.     starname[i] = i;
  197.   }
  198.  
  199.   /* Sort the index list if -Uz, -Ul, -Un, or -Ub switch in effect. */
  200.  
  201.   if (us.nStar > 1) for (i = 2; i <= cStar; i++) {
  202.     j = i-1;
  203.  
  204.     /* Compare star names for -Un switch. */
  205.  
  206.     if (us.nStar == 'n') while (j > 0 && NCompareSz(
  207.       szObjName[oNorm+starname[j]], szObjName[oNorm+starname[j+1]]) > 0) {
  208.       SwapN(starname[j], starname[j+1]);
  209.       j--;
  210.  
  211.     /* Compare star brightnesses for -Ub switch. */
  212.  
  213.     } else if (us.nStar == 'b') while (j > 0 &&
  214.       starbright[starname[j]] > starbright[starname[j+1]]) {
  215.       SwapN(starname[j], starname[j+1]);
  216.       j--;
  217.  
  218.     /* Compare star zodiac locations for -Uz switch. */
  219.  
  220.     } else if (us.nStar == 'z') while (j > 0 &&
  221.       planet[oNorm+starname[j]] > planet[oNorm+starname[j+1]]) {
  222.       SwapN(starname[j], starname[j+1]);
  223.       j--;
  224.  
  225.     /* Compare star declinations for -Ul switch. */
  226.  
  227.     } else if (us.nStar == 'l') while (j > 0 &&
  228.       planetalt[oNorm+starname[j]] < planetalt[oNorm+starname[j+1]]) {
  229.       SwapN(starname[j], starname[j+1]);
  230.       j--;
  231.     }
  232.   }
  233. }
  234.  
  235.  
  236. /*
  237. ******************************************************************************
  238. ** Chart Calculation.
  239. ******************************************************************************
  240. */
  241.  
  242. /* Given a zodiac degree, transform it into its Decan sign, where each    */
  243. /* sign is trisected into the three signs of its element. For example,    */
  244. /* 1 Aries -> 3 Aries, 10 Leo -> 0 Sagittarius, 25 Sagittarius -> 15 Leo. */
  245.  
  246. real Decan(deg)
  247. real deg;
  248. {
  249.   int sign;
  250.   real unit;
  251.  
  252.   sign = SFromZ(deg);
  253.   unit = deg - ZFromS(sign);
  254.   sign = Mod12(sign + 4*((int)RFloor(unit/10.0)));
  255.   unit = (unit - RFloor(unit/10.0)*10.0)*3.0;
  256.   return ZFromS(sign)+unit;
  257. }
  258.  
  259.  
  260. /* Transform spherical to rectangular coordinates in x, y, z. */
  261.  
  262. void SphToRec(r, azi, alt, rx, ry, rz)
  263. real r, azi, alt, *rx, *ry, *rz;
  264. {
  265.   real rT;
  266.  
  267.   *rz = r *RSinD(alt);
  268.   rT  = r *RCosD(alt);
  269.   *rx = rT*RCosD(azi);
  270.   *ry = rT*RSinD(azi);
  271. }
  272.  
  273.  
  274. #ifdef PLACALC
  275. /* Compute the positions of the planets at a certain time using the Placalc */
  276. /* accurate formulas and ephemeris. This will superseed the Matrix routine  */
  277. /* values and is only called with the -b switch is in effect. Not all       */
  278. /* objects or modes are available using this, but some additional values    */
  279. /* such as Moon and Node velocities not available without -b are. (This is  */
  280. /* the one place in Astrolog which calls the Placalc package functions.)    */
  281.  
  282. void ComputePlacalc(t)
  283. real t;
  284. {
  285.   int i;
  286.   real r1, r2, r3, r4;
  287.  
  288.   /* We can compute the positions of Sun through Pluto, Chiron, and the  */
  289.   /* North Node using Placalc. The other objects must be done elsewhere. */
  290.  
  291.   for (i = oSun; i <= oLil; i++) {
  292.     if ((i > oChi && i < oNod) || (ignore[i] && i > oMoo))
  293.       continue;
  294.     if (FPlacalcPlanet(i, t*36525.0+2415020.0, us.objCenter != oSun,
  295.       &r1, &r2, &r3, &r4)) {
  296.  
  297.       /* Note that this can't compute charts with central planets other */
  298.       /* than the Sun or Earth or relative velocities in current state. */
  299.  
  300.       planet[i]    = Mod(r1 + is.rSid);
  301.       planetalt[i] = r2;
  302.       ret[i]       = RFromD(r3);
  303.  
  304.       /* Compute x,y,z coordinates from azimuth, altitude, and distance. */
  305.  
  306.       SphToRec(r4, planet[i], planetalt[i],
  307.         &spacex[i], &spacey[i], &spacez[i]);
  308.     }
  309.   }
  310. }
  311. #endif
  312.  
  313.  
  314. /* This is probably the main routine in all of Astrolog. It generates a   */
  315. /* chart, calculating the positions of all the celestial bodies and house */
  316. /* cusps, based on the current chart information, and saves them for use  */
  317. /* by any of the display routines.                                        */
  318.  
  319. real CastChart(fDate)
  320. bool fDate;
  321. {
  322.   CI ci;
  323.   real housetemp[cSign+1], Off = 0.0, vtx, j;
  324.   int i, k;
  325.  
  326.   /* Hack: Time zone +/-24 means to have the time of day be in Local Mean */
  327.   /* Time (LMT). This is done by making the time zone value reflect the   */
  328.   /* logical offset from GMT as indicated by the chart's longitude value. */
  329.  
  330.   if (RAbs(ZZ) == 24.0)
  331.     ZZ = DecToDeg(OO)/15.0;
  332.   ci = ciCore;
  333.  
  334.   if (MM == -1) {
  335.  
  336.     /* Hack: If month is negative, then we know chart was read in through a  */
  337.     /* -o0 position file, so the planet positions are already in the arrays. */
  338.  
  339.     MC = planet[oMC]; Asc = planet[oAsc];
  340.   } else {
  341.     for (i = 1; i <= cObj; i++) {
  342.       planet[i] = planetalt[i] = 0.0;    /* On ecliptic unless we say so.  */
  343.       ret[i] = 1.0;                      /* Direct until we say otherwise. */
  344.     }
  345.     Off = ProcessInput(fDate);
  346.     ComputeVariables(&vtx);
  347.     if (us.fGeodetic)               /* Check for -G geodetic chart. */
  348.       RA = RFromD(Mod(-OO));
  349.     MC  = CuspMidheaven();          /* Calculate our Ascendant & Midheaven. */
  350.     Asc = CuspAscendant();
  351.     ComputeHouses(us.nHouseSystem); /* Go calculate house cusps. */
  352.  
  353.     /* Go calculate planet, Moon, and North Node positions. */
  354.  
  355.     ComputePlanets();
  356.     if (!ignore[oMoo] || !ignore[oNod] || !ignore[oSou] || !ignore[oFor]) {
  357.       ComputeLunar(&planet[oMoo], &planetalt[oMoo],
  358.         &planet[oNod], &planetalt[oNod]);
  359.       ret[oNod] = -1.0;
  360.     }
  361.  
  362.     /* Compute more accurate ephemeris positions for certain objects. */
  363.  
  364. #ifdef PLACALC
  365.     if (us.fPlacalc)
  366.       ComputePlacalc(T);
  367. #endif
  368.     if (!us.fPlacalc) {
  369.       planet[oSou] = Mod(planet[oNod]+rDegHalf);
  370.       ret[oSou] = ret[oNod] = RFromD(-0.053);
  371.       ret[oMoo] = RFromD(12.5);
  372.     }
  373.  
  374.     /* Calculate position of Part of Fortune. */
  375.  
  376.     j = planet[oMoo]-planet[oSun];
  377.     if (us.nArabicNight < 0)
  378.       neg(j);
  379.     j = RAbs(j) < rDegQuad ? j : j - RSgn(j)*rDegMax;
  380.     planet[oFor] = Mod(j+Asc);
  381.  
  382.     /* Fill in "planet" positions corresponding to house cusps. */
  383.  
  384.     planet[oVtx] = vtx; planet[oEP] = CuspEastPoint();
  385.     for (i = 2; i <= cSign; i++)
  386.       planet[cuspLo + i - 1] = house[i];
  387.     planet[oAsc] = Asc; planet[oMC] = MC;
  388.     planet[oDes] = Mod(Asc + rDegHalf); planet[oNad] = Mod(MC + rDegHalf);
  389.     for (i = oFor; i <= cuspHi; i++)
  390.       ret[i] = RFromD(rDegMax);
  391.   }
  392.  
  393.   /* Go calculate star positions if -U switch in effect. */
  394.  
  395.   if (us.nStar)
  396.     ComputeStars(us.fSiderial ? 0.0 : -Off);
  397.  
  398.   /* Transform ecliptic to equatorial coordinates if -sr in effect. */
  399.  
  400.   if (us.fEquator)
  401.     for (i = 1; i <= cObj; i++) if (!ignore[i]) {
  402.       planet[i]    = RFromD(Tropical(planet[i]));
  403.       planetalt[i] = RFromD(planetalt[i]);
  404.       EclToEqu(&planet[i], &planetalt[i]);
  405.       planet[i]    = DFromR(planet[i]);
  406.       planetalt[i] = DFromR(planetalt[i]);
  407.     }
  408.  
  409.   /* Now, we may have to modify the base positions we calculated above based */
  410.   /* on what type of chart we are generating.                                */
  411.  
  412.   if (us.fProgress && us.fSolarArc) { /* Are we doing a -p0 solar arc chart? */
  413.     for (i = 1; i <= cObj; i++)
  414.       planet[i] = Mod(planet[i] + (is.JDp - is.JD) / us.rProgDay);
  415.     for (i = 1; i <= cSign; i++)
  416.       house[i]  = Mod(house[i]  + (is.JDp - is.JD) / us.rProgDay);
  417.     }
  418.   if (us.nHarmonic > 1)             /* Are we doing a -x harmonic chart?     */
  419.     for (i = 1; i <= cObj; i++)
  420.       planet[i] = Mod(planet[i] * (real)us.nHarmonic);
  421.   if (us.objOnAsc) {
  422.     if (us.objOnAsc > 0)            /* Is -1 put on Ascendant in effect?     */
  423.       j = planet[us.objOnAsc]-Asc;
  424.     else                            /* Or -2 put object on Midheaven switch? */
  425.       j = planet[-us.objOnAsc]-MC;
  426.     for (i = 1; i <= cSign; i++)    /* If so, rotate the houses accordingly. */
  427.       house[i] = Mod(house[i]+j);
  428.   }
  429.  
  430.   /* Check to see if we are -F forcing any objects to be particular values. */
  431.  
  432.   for (i = 1; i <= cObj; i++)
  433.     if (force[i] != 0.0) {
  434.       planet[i] = force[i]-rDegMax;
  435.       planetalt[i] = ret[i] = 0.0;
  436.     }
  437.  
  438.   ComputeInHouses();        /* Figure out what house everything falls in. */
  439.  
  440.   /* If -f domal chart switch in effect, switch planet and house positions. */
  441.  
  442.   if (us.fFlip) {
  443.     for (i = 1; i <= cObj; i++) {
  444.       k = inhouse[i];
  445.       inhouse[i] = SFromZ(planet[i]);
  446.       planet[i] = ZFromS(k)+MinDistance(house[k], planet[i]) /
  447.         MinDistance(house[k], house[Mod12(k+1)])*30.0;
  448.     }
  449.     for (i = 1; i <= cSign; i++) {
  450.       k = HousePlaceIn(ZFromS(i));
  451.       housetemp[i] = ZFromS(k)+MinDistance(house[k], ZFromS(i)) /
  452.         MinDistance(house[k], house[Mod12(k+1)])*30.0;
  453.     }
  454.     for (i = 1; i <= cSign; i++)
  455.       house[i] = housetemp[i];
  456.   }
  457.  
  458.   /* If -3 decan chart switch in effect, edit planet positions accordingly. */
  459.  
  460.   if (us.fDecan) {
  461.     for (i = 1; i <= cObj; i++)
  462.       planet[i] = Decan(planet[i]);
  463.     ComputeInHouses();
  464.   }
  465.  
  466.   ciCore = ci;
  467.   return T;
  468. }
  469.  
  470.  
  471. /*
  472. ******************************************************************************
  473. ** Aspect Calculations.
  474. ******************************************************************************
  475. */
  476.  
  477. /* Set up the aspect/midpoint grid. Allocate memory for this array, if not */
  478. /* already done. Allocation is only done once, first time this is called.  */
  479.  
  480. bool FEnsureGrid()
  481. {
  482.   if (grid != NULL)
  483.     return fTrue;
  484.   grid = (GridInfo FAR *)PAllocate(sizeof(GridInfo), fFalse, "grid");
  485.   return grid != NULL;
  486. }
  487.  
  488.  
  489. /* Indicate whether some aspect between two objects should be shown. */
  490.  
  491. bool FAcceptAspect(obj1, asp, obj2)
  492. int obj1, asp, obj2;
  493. {
  494.   int fSupp;
  495.  
  496.   if (ignorea(asp))    /* If the aspect restricted, reject immediately. */
  497.     return fFalse;
  498.   if (us.fSmartCusp) {
  499.  
  500.     /* Allow only conjunctions to the minor house cusps. */
  501.  
  502.     if ((FMinor(obj1) || FMinor(obj2)) && asp > aCon)
  503.       return fFalse;
  504.  
  505.     /* Prevent any simultaneous aspects to opposing angle cusps,     */
  506.     /* e.g. if conjunct one, don't be opposite the other; if trine   */
  507.     /* one, don't sextile the other; don't square both at once, etc. */
  508.  
  509.     fSupp = (asp == aOpp || asp == aSex || asp == aSSx || asp == aSes);
  510.     if ((FAngle(obj1) || FAngle(obj2)) &&
  511.       (fSupp || (asp == aSqu &&
  512.       (obj1 == oDes || obj2 == oDes || obj1 == oNad || obj2 == oNad))))
  513.       return fFalse;
  514.  
  515.     /* Prevent any simultaneous aspects to the North and South Node. */
  516.  
  517.     if (fSouthNode) {
  518.       if (((obj1 == oNod || obj2 == oNod) && fSupp) ||
  519.         ((obj1 == oSou || obj2 == oSou) && (fSupp || asp == aSqu)))
  520.         return fFalse;
  521.     }
  522.   }
  523.   return fTrue;
  524. }
  525.  
  526.  
  527. /* This is a subprocedure of FCreateGrid() and FCreateGridRelation().   */
  528. /* Given two planets, determine what aspect, if any, is present between */
  529. /* them, and save the aspect name and orb in the specified grid cell.   */
  530.  
  531. void GetAspect(planet1, planet2, ret1, ret2, i, j)
  532. real *planet1, *planet2, *ret1, *ret2;
  533. int i, j;
  534. {
  535.   int k;
  536.   real l, m;
  537.  
  538.   grid->v[i][j] = grid->n[i][j] = 0;
  539.   l = MinDistance(planet2[i], planet1[j]);
  540.   for (k = us.nAsp; k >= 1; k--) {
  541.     if (!FAcceptAspect(i, k, j))
  542.       continue;
  543.     m = l-aspectangle[k];
  544.     if (RAbs(m) < GetOrb(i, j, k)) {
  545.       grid->n[i][j] = k;
  546.  
  547.       /* If -ga switch in effect, then change the sign of the orb to    */
  548.       /* correspond to whether the aspect is applying or separating.    */
  549.       /* To do this, we check the velocity vectors to see if the        */
  550.       /* planets are moving toward, away, or are overtaking each other. */
  551.  
  552.       if (us.fAppSep)
  553.         m = RSgn2(ret1[j]-ret2[i])*
  554.           RSgn2(MinDifference(planet2[i], planet1[j]))*RSgn2(m)*RAbs(m);
  555.       grid->v[i][j] = (int)(m*60.0);
  556.     }
  557.   }
  558. }
  559.  
  560.  
  561. /* Very similar to GetAspect(), this determines if there is a parallel or */
  562. /* contraparallel aspect between the given two planets, and stores the    */
  563. /* result as above. The settings and orbs for conjunction are used for    */
  564. /* parallel and those for opposition are used for contraparallel.         */
  565.  
  566. void GetParallel(planet1, planet2, planetalt1, planetalt2, i, j)
  567. real *planet1, *planet2, *planetalt1, *planetalt2;
  568. int i, j;
  569. {
  570.   int k;
  571.   real l, alt1, alt2;
  572.  
  573.   l = RFromD(planet1[j]); alt1 = RFromD(planetalt1[j]);
  574.   EclToEqu(&l, &alt1); alt1 = DFromR(alt1);
  575.   l = RFromD(planet2[i]); alt2 = RFromD(planetalt2[i]);
  576.   EclToEqu(&l, &alt2); alt2 = DFromR(alt2);
  577.   grid->v[i][j] = grid->n[i][j] = 0;
  578.   for (k = Min(us.nAsp, aOpp); k >= 1; k--) {
  579.     if (!FAcceptAspect(i, k, j))
  580.       continue;
  581.     l = RAbs(k == aCon ? alt1 - alt2 : RAbs(alt1) - RAbs(alt2));
  582.     if (l < GetOrb(i, j, k)) {
  583.       grid->n[i][j] = k;
  584.       grid->v[i][j] = (int)(l*60.0);
  585.     }
  586.   }
  587. }
  588.  
  589.  
  590. /* Fill in the aspect grid based on the aspects taking place among the */
  591. /* planets in the present chart. Also fill in the midpoint grid.       */
  592.  
  593. bool FCreateGrid(fFlip)
  594. bool fFlip;
  595. {
  596.   int i, j, k;
  597.   real l;
  598.  
  599.   if (!FEnsureGrid())
  600.     return fFalse;
  601.   for (j = 1; j <= cObj; j++) if (!ignore[j])
  602.     for (i = 1; i <= cObj; i++) if (!ignore[i])
  603.  
  604.       /* The parameter 'flip' determines what half of the grid is filled in */
  605.       /* with the aspects and what half is filled in with the midpoints.    */
  606.  
  607.       if (fFlip ? i > j : i < j) {
  608.         if (us.fParallel)
  609.           GetParallel(planet, planet, planetalt, planetalt, i, j);
  610.         else
  611.           GetAspect(planet, planet, ret, ret, i, j);
  612.       } else if (fFlip ? i < j : i > j) {
  613.         l = Mod(Midpoint(planet[i], planet[j])); k = (int)l;  /* Calculate */
  614.         grid->n[i][j] = k/30+1;                               /* midpoint. */
  615.         grid->v[i][j] = (int)((l-(real)(k/30)*30.0)*60.0);
  616.       } else {
  617.         grid->n[i][j] = SFromZ(planet[j]);
  618.         grid->v[i][j] = (int)(planet[j]-(real)(grid->n[i][j]-1)*30.0);
  619.       }
  620.   return fTrue;
  621. }
  622.  
  623.  
  624. /* This is similar to the previous function; however, this time fill in the */
  625. /* grid based on the aspects (or midpoints if 'acc' set) taking place among */
  626. /* the planets in two different charts, as in the -g -r0 combination.       */
  627.  
  628. bool FCreateGridRelation(fMidpoint)
  629. bool fMidpoint;
  630. {
  631.   int i, j, k;
  632.   real l;
  633.  
  634.   if (!FEnsureGrid())
  635.     return fFalse;
  636.   for (j = 1; j <= cObj; j++) if (!ignore[j])
  637.     for (i = 1; i <= cObj; i++) if (!ignore[i])
  638.       if (!fMidpoint) {
  639.         if (us.fParallel)
  640.           GetParallel(cp1.obj, cp2.obj, cp1.alt, cp2.alt, i, j);
  641.         else
  642.           GetAspect(cp1.obj, cp2.obj, cp1.dir, cp2.dir, i, j);
  643.       } else {
  644.         l = Mod(Midpoint(cp2.obj[i], cp1.obj[j])); k = (int)l; /* Calculate */
  645.         grid->n[i][j] = k/30+1;                                /* midpoint. */
  646.         grid->v[i][j] = (int)((l-(real)(k/30)*30.0)*60.0);
  647.       }
  648.   return fTrue;
  649. }
  650.  
  651.  
  652. /* Fill out tables based on the number of unrestricted planets in signs by  */
  653. /* element, signs by mode, as well as other values such as the number of    */
  654. /* objects in yang vs. yin signs, in various house hemispheres (north/south */
  655. /* and east/west), and the number in first six signs vs. second six signs.  */
  656. /* This is used by the -v chart listing and the sidebar in graphics charts. */
  657.  
  658. void CreateElemTable(pet)
  659. ET *pet;
  660. {
  661.   int i, s;
  662.  
  663.   ClearB((lpbyte)pet, (int)sizeof(ET));
  664.   for (i = 1; i <= cObj; i++) if (!ignore[i]) {
  665.     pet->coSum++;
  666.     s = SFromZ(planet[i]);
  667.     pet->coSign[s-1]++;
  668.     pet->coElemMode[(s-1)&3][(s-1)%3]++;
  669.     pet->coElem[(s-1)&3]++; pet->coMode[(s-1)%3]++;
  670.     pet->coYang += (s & 1);
  671.     pet->coLearn += (s < sLib);
  672.     if (!FCusp(i)) {
  673.       pet->coHemi++;
  674.       s = inhouse[i];
  675.       pet->coHouse[s-1]++;
  676.       pet->coModeH[(s-1)%3]++;
  677.       pet->coMC += (s >= sLib);
  678.       pet->coAsc += (s < sCan || s >= sCap);
  679.     }
  680.   }
  681.   pet->coYin   = pet->coSum  - pet->coYang;
  682.   pet->coShare = pet->coSum  - pet->coLearn;
  683.   pet->coDes   = pet->coHemi - pet->coAsc;
  684.   pet->coIC    = pet->coHemi - pet->coMC;
  685. }
  686.  
  687. /* calc.c */
  688.